#ifndef USERINTERFACE_H
#define USERINTERFACE_H

#include <QWidget>
#include <QDragEnterEvent>
#include <QDropEvent>
#include <QMimeData>
#include <QFile>
#include <QFileDialog>
#include <QBuffer>
#include <QString>

#include <QMutex>
#include <QImageReader>
#include "pack.h"
#include "abs.h"
#include "mythread.h"
#include "schedule.h"
#include "mymessage.h"
#include "audioinput.h"
#include "audiooutput.h"
namespace Ui {
class Userinterface;
}

class Userinterface : public QWidget
{
    Q_OBJECT

public:
    explicit Userinterface(QWidget *parent = nullptr);
    ~Userinterface();
    void setLoginInterface(QWidget* w); // 用来设置接受登录界面指针的一个函数
    void setClient(QTcpSocket* client);
    void setSchedule(schedule* s) { sche = s; }
    QTcpSocket* getClient() const {
        return client;
    }
    myMessage* getMyMessage() { return msg; }
    void setMyMessage(myMessage* message) { msg = message; }
    void setcurrentUsername(QString name){currentUsername=name;}
    void setPic(QPixmap& pic);
    void showImage(QByteArray *image);

    void setDeskPic(QPixmap &pic);
    void setCamerPic(QPixmap &pic);
private slots:

    void on_pushButton_clicked();

    void on_pushButton_2_clicked();

    void on_pushButton_3_clicked();

    void on_pushButton_4_clicked();

    void on_pushButton_5_clicked();

    void on_pushButton_6_clicked();
    
    void on_pushButton_7_clicked();

    void on_pushButton_message_clicked();

    void on_pushButton_8_clicked();

    void on_pushButton_9_clicked();


protected:
    virtual void dragEnterEvent(QDragEnterEvent *event) override;
    virtual void dropEvent(QDropEvent *event) override;

public slots:
    void recvImage(QImage& image);// 用来接受Abs 通过信号发来的图片的槽函数
    void recvDesk(QPixmap pic);
    void onMessageWindowClosed(); // 新增：消息窗口关闭时调用
    void textshow(QString currentUsername,QString text);

    void getnum(int n){num=n;}


    void handleAudioData(const QByteArray& audioData);
private:
    Ui::Userinterface *ui;
    QWidget* loginInterface;
    QTcpSocket* client;
    QFile file;
    Abs* abs;
    myThread* thread;
    schedule* sche=nullptr;
    myMessage* msg=nullptr;
    QString currentUsername;


    QMutex bufferMutex;
    AudioInput* audioInput;
    AudioOutput* audioOutput;
    int num;
};

#endif // USERINTERFACE_H
